package com.kcs.fxmargin.dao;

import java.sql.*;
import org.apache.log4j.Logger;
import com.kcs.common.utils.Constant;
import com.kcs.fxmargin.bo.MainPageBO;

public class MainPageDAO {
	private Logger log = Logger.getLogger(Constant.LOG_FX);
	
	public MainPageBO getActionRoleFlag(MainPageBO model, Connection conn)throws Exception{
		PreparedStatement pstmt = null;
        ResultSet rs = null;
        String sql = null;
        
        log.info("Begin : MainPageDAO : getActionRoleFlag");
        
        try{
            sql =  "select * "+
            	   " from m_menu m, "+
            		" m_users_auth ma "+
            		" where m.id = ma.menu_id "+
            		" and m.url like ? "+
            		" and ma.role_id = ?";
            
            log.debug(sql);
            System.out.println("<- actionPath: "+model.getActionPath());
            System.out.println("<- roleId: "+model.getRoleId());
            
            pstmt = conn.prepareStatement(sql);
            pstmt.setString(1, "%"+model.getActionPath()+"%");
            pstmt.setString(2, model.getRoleId());
            rs = pstmt.executeQuery();
            
            if(rs != null){      	
	            while(rs.next()){
	            	model.setFlag(rs.getString("flag"));
	            }
            }
            
            log.info("flag : "+model.getFlag());
            
        }catch(Exception e){
            throw e;
        }finally{
	        if(pstmt != null){
	            try{
	                pstmt.close();
	            }catch(Exception ex){
	                throw ex;
	            }
	        }
	        if(rs != null)
	            try{
	                rs.close();
	            }catch(Exception ex){
	                throw ex;
	            }
        }
       
        log.info("End : MainPageDAO : getActionRoleFlag");
        return model;
	}
	
	public String convertToString(Object ob){
		return (ob==null)?"":ob.toString();
	}
	
}